using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using BG.Data;
using Kwan.Data;

namespace BG.Service
{
    public class ArticleQuery
	{
        public static Expression MakeSearchWhere(NameValueCollection ps)
		{
            Expression exp = new Expression();

            string propName = "EntityID";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.entityID == int.Parse(ps[propName]);

            propName = "Cid";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.cid == int.Parse(ps[propName]);

            //propName = "click";
            //if (!string.IsNullOrEmpty(ps[propName]))
            //    exp &= TArticle.click == int.Parse(ps[propName]);

            propName = "createdDate";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.createdDate > ps[propName];

            propName = "hot";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.hot == bool.Parse(ps[propName]);

            propName = "Content";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.content.Like(ps[propName]);

            propName = "Enable";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.enable == bool.Parse(ps[propName]);

            propName = "tag";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.title.Like(ps[propName])
                    | TArticle.content.Like(ps[propName])
                    | TArticle.keyword.Like(ps[propName]);

            propName = "English";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.english == bool.Parse(ps[propName]);

            propName = "FilePath";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.filePath == ps[propName];
            propName = "Image";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.image == ps[propName];
            propName = "Keyword";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.keyword == ps[propName];
            propName = "Sort";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.sort == ps[propName];
            propName = "Source";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.source == ps[propName];
            propName = "Title";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TArticle.title.Like(ps[propName]);

            return exp;
		}
	}
}